/*
 *  A solution to topcoder SRM 203 Div 1 Prob 1
 */

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;


public class MatchMaking
{
    int score (String s1, String s2) {
	int ans = 0;
	for (int i = 0; i < s1.length (); ++i)
	    if (s1.charAt (i) == s2.charAt (i))
		++ans;
	return ans;
    }
    
    /* Sort name and remember index by hashmap. */
    void sortName (String[] names, String[] answers) {
	HashMap<String, Integer> nameMap = new HashMap<String, Integer> ();
	for (int i = 0; i < names.length; ++i)
	    nameMap.put (names[i], i);
	Arrays.sort (names);
	String[] copy = (String[])answers.clone ();
	for (int i = 0; i < names.length; ++i) 
	    answers[i] = copy[nameMap.get (names[i])];
    }
    

    public String makeMatch(String[] namesWomen, String[] answersWomen, String[] namesMen, String[] answersMen, String queryWoman)
    {
	sortName (namesWomen,answersWomen);
	sortName (namesMen, answersMen);
	String ans = "";
	for (int i = 0; i < namesWomen.length; ++i) {
	    String s1 = answersWomen[i];
	    int scores = Integer.MIN_VALUE;
	    int choise = -1;
	    for (int j = 0; j < namesMen.length; ++j) {
		if (namesMen[j] == null)
		    continue;
		if (score (s1, answersMen[j]) > scores) {
		    scores = score (s1, answersMen[j]);
		    ans = namesMen[j];
		    choise = j;
		}
	    }
	    if (namesWomen[i].equals (queryWoman)) {
		return ans;
	    }
	    namesMen[choise] = null;
	}
	return null;
    }
    
    <%:testing-code%>
}
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!